package com.agricultural.robot.model;

/**
 * 喷药机 - 具体农机类型
 */
public class Sprayer extends AgriculturalMachine {
    private double sprayerHeight;
    private double chemicalAmount;

    public Sprayer(String name) {
        super(name);
        this.sprayerHeight = 1.0; // 默认喷药高度(米)
        this.chemicalAmount = 100.0; // 初始药量(升)
    }

    public double getSprayerHeight() {
        return sprayerHeight;
    }

    public void setSprayerHeight(double sprayerHeight) {
        this.sprayerHeight = sprayerHeight;
        System.out.println(getName() + " 喷药高度调整为: " + sprayerHeight + "米");
    }

    public double getChemicalAmount() {
        return chemicalAmount;
    }

    public void setChemicalAmount(double chemicalAmount) {
        this.chemicalAmount = chemicalAmount;
        System.out.println(getName() + " 药量更新为: " + chemicalAmount + "升");
    }

    @Override
    public void performTask(Task task) {
        if (task instanceof SprayingTask) {
            SprayingTask sprayingTask = (SprayingTask) task;
            System.out.println(getName() + " 开始执行喷药任务: " + sprayingTask.getChemicalType() + " 在 " + sprayingTask.getFieldArea());
            System.out.println("喷药高度: " + sprayerHeight + "米");
            consumeBattery(8.0);
            setChemicalAmount(chemicalAmount - 5.0);
        } else {
            System.out.println(getName() + " 无法执行该类型任务: " + task.getClass().getSimpleName());
        }
    }

    @Override
    public void update(EnvironmentData data) {
        super.update(data);
        // 根据风速调整喷药高度
        if (data.getWindSpeed() > 5.0) {
            setSprayerHeight(sprayerHeight * 0.8); // 风速大降低高度
        } else if (data.getWindSpeed() < 2.0) {
            setSprayerHeight(sprayerHeight * 1.2); // 风速小增加高度
        }
    }
}
